package codegen.ui.jung;

import edu.uci.ics.jung.algorithms.layout.FRLayout;
import edu.uci.ics.jung.graph.SparseMultigraph;
import edu.uci.ics.jung.visualization.VisualizationViewer;
import edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse;
import edu.uci.ics.jung.visualization.control.SatelliteVisualizationViewer;
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JComponent;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import codegen.graphnetwork.model.*;

/**
 *
 * @author cuong.nguyenmanh2
 */
public class GraphTest {

    SparseMultigraph<Node, Link> graph;
    private VisualizationViewer<Node, Link> vv;
    private SatelliteVisualizationViewer birdeye;
    private final DefaultModalGraphMouse<Node, Link> gm;

    public GraphTest() {
        graph = new SparseMultigraph<Node, Link>();

        createGraph();
        FRLayout<Node, Link> layout = new FRLayout<Node, Link>(graph);
//layout.setSize(new Dimension(5000,5000));
        vv = new VisualizationViewer<Node, Link>(layout);
//PickedState<Integer> picked_state = vv.getPickedVertexState();
        gm = new DefaultModalGraphMouse<Node, Link>();
        vv.setGraphMouse(gm);
        vv.setBackground(Color.white);
// create the BirdsEyeView for zoom/pan
        birdeye = new SatelliteVisualizationViewer(vv);
        vv.getRenderer().setVertexRenderer(new GroovyGraphicsRenderer());
    }

    public JComponent getView() {
        return this.vv;
    }

    public JComponent getBirdEyeView() {
        return this.birdeye;
    }

    public void createGraph() {

// Init the graph
        /*
         graph.addVertex(1);
         graph.addVertex(2);
         graph.addVertex(3);
         graph.addVertex(4);
         */
        Node n1 = new Node("Node1");

        n1.addInput(new Value("Int", "value1", 1));
        n1.addInput(new Value("Int", "value2", 2));
        n1.addOutput(new Value("Int", "Result", 0));


        Node n2 = new Node("Node2");
        n2.addInput(new Value("Int", "value1", 0));
        n2.addInput(new Value("Int", "value2", 0));
        n2.addOutput(new Value("Int", "Result", 0));

        Node n3 = new Node("Node3");
        n3.addInput(new Value("Int", "value1", 3));
        n3.addInput(new Value("Int", "value2", 4));
        n3.addOutput(new Value("Int", "Result", 0));

        graph.addVertex(n1);
        graph.addVertex(n2);
        graph.addVertex(n3);
    }
    
        
    public static void main(String[] args) {
        GraphTest graphTest = new GraphTest();
        //graphTest.createScene();
        JFrame testFrame = new JFrame("Test NB graph");
        testFrame.setLayout(new BorderLayout());
        testFrame.add(graphTest.getView());
        testFrame.setSize(new Dimension(800, 600));
        testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        testFrame.setVisible(true);
    }
}
